/**
 * 详情对话框
 */
var TProposedMeasuresPlanInfoDlg = {
    data: {
        companyId: "",
        planId: "",
        readyTime: "",
        emissionReductionEstimates: "",
        remark: "",
        delFlag: "",
        planDesc:""


    }
};

layui.use(['form', 'admin','laydate', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;

    //让当前iframe弹层高度适应
    admin.iframeAuto();




    /*监听措施*/
    var ajax1 = new $ax(Feng.ctxPath + "/vocReducingPlan/planList");
    var planList = ajax1.start();
    for (var i = 0 ; i < planList.length ; i++){
        $("select#planId").append("<option value=\"" + planList[i].id + "\">" + planList[i].planType + "</option>");
    }
    //重新渲染
    layui.form.render("select");





    //监听是否选择措施计划

    form.on('select(planId)', function (data) {
        console.log(data.elem); //得到select原始DOM对象
        console.log(data.value); //得到被选中的值
        console.log(data.othis); //得到美化后的DOM对象
        var  sb = document.getElementById("plans");
        console.log(sb); //得到select原始DOM对象
        if (data.value == null) {
            sb.style.display = "none"
            // $('#reasons').style.display ="none";
        }else {
            // $('#reasons').style.display = "block";
            sb.style.display = "block"
        }
    });



    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/tProposedMeasuresPlan/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('tProposedMeasuresPlanForm', result.data);
    if (result.data.planId!=null&&result.data.planId!=""){
        var  sb = document.getElementById("plans");
            sb.style.display = "block"
        } else {
            sb.style.display = "none"
        }




    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/tProposedMeasuresPlan/editItem", function (data) {
            if(data.code == 200) {
                Feng.success("更新成功！");
            }else{
                Feng.error("更新失败！" + data.message)
            }

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();

        }, function (data) {
            Feng.error("更新失败！" + data.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });



    // 渲染时间选择框
    laydate.render({
        elem: '#readyTime'
    });




});